﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter2.Section1
{
    public class Example04
    {
        public Example04()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double, double, double[]> cf
                = new V.Function.ToLastType<double, double, double[]>(Box);
            V.Domain2D xd = new V.Domain2D();
            xd.ConditionFunctionsLessThanZero = cf;
            xd.LowerBoundOfX = -1.0;
            xd.LowerBoundOfY = -1.0;
            xd.UpperBoundOfX = 1.0;
            xd.UpperBoundOfY = 1.0;

            V.Function.ToLastType<double, double, double> f
                = new V.Function.ToLastType<double, double, double>(func);
            V.LevelCurve ls = new V.LevelCurve(f, -0.5, xd);
            ls.FindCurve(0.01);

            for (int i = 0; i < ls.CurvePointX.Count; i++)
            {
                result += ls.CurvePointX[i].ToString() + "\t";
                result += ls.CurvePointY[i].ToString() + "\r\n";
            }
        }
        private double func(double x, double y)
        {
            return x * x - y * y;
        }
        private double[] Box(double x, double y)
        {
            double[] f = new double[1];
            f[0] = - 1.0;
            return f;
        }
    }
}

/*
-0.70709219858156	-1
-0.7	-0.994974874371859
-0.692877697841727	-0.99
-0.69	-0.987969543147208
-0.69	0.987969543147208
-0.68	-0.981015228426396
-0.678518518518518	-0.98
-0.678518518518518	0.98
-0.68	0.981015228426396
-0.67	-0.974102564102564
-0.663984962406015	-0.97
-0.663984962406015	0.97
-0.67	0.974102564102564
-0.66	-0.967253886010363
-0.66	0.967253886010363
-0.65	-0.960466321243523
-0.649302325581395	-0.96
-0.649302325581395	0.96
-0.65	0.960466321243523
-0.64	-0.953717277486911
-0.634409448818898	-0.95
-0.634409448818898	0.95
-0.64	0.953717277486911
-0.63	-0.947037037037037
-0.63	0.947037037037037
-0.62	-0.94042328042328
-0.619349593495935	-0.94
-0.619349593495935	0.94
-0.62	0.94042328042328
-0.61	-0.933850267379679
-0.604049586776859	-0.93
-0.604049586776859	0.93
-0.61	0.933850267379679
-0.6	-0.927351351351351
-0.6	0.927351351351351
-0.59	-0.920918918918919
-0.588547008547009	-0.92
-0.588547008547008	0.92
-0.59	0.920918918918919
-0.58	-0.914535519125683
-0.572782608695652	-0.91
-0.572782608695652	0.91
-0.58	0.914535519125683
-0.57	-0.908232044198895
-0.57	0.908232044198895
-0.56	-0.901988950276243
-0.556756756756757	-0.9
-0.556756756756757	0.9
-0.56	0.901988950276243
-0.55	-0.895810055865922
-0.54045871559633	-0.89
-0.540458715596331	0.89
-0.55	0.895810055865922
-0.54	-0.889717514124294
-0.54	0.889717514124294
-0.53	-0.883672316384181
-0.523809523809524	-0.88
-0.523809523809524	0.88
-0.53	0.883672316384181
-0.52	-0.877714285714286
-0.52	0.877714285714286
-0.51	-0.871828571428571
-0.506831683168317	-0.87
-0.506831683168317	0.87
-0.51	0.871828571428571
-0.5	-0.866011560693642
-0.5	0.866011560693642
-0.49	-0.86028901734104
-0.489484536082474	-0.86
-0.489484536082474	0.86
-0.49	0.86028901734104
-0.48	-0.854619883040936
-0.471684210526316	-0.85
-0.471684210526316	0.85
-0.48	0.854619883040936
-0.47	-0.84905325443787
-0.47	0.84905325443787
-0.46	-0.843550295857988
-0.453406593406593	-0.84
-0.453406593406594	0.84
-0.46	0.843550295857988
-0.45	-0.83814371257485
-0.45	0.83814371257485
-0.44	-0.832814371257485
-0.434597701149425	-0.83
-0.434597701149425	0.83
-0.44	0.832814371257485
-0.43	-0.827575757575758
-0.43	0.827575757575758
-0.42	-0.822424242424242
-0.415180722891566	-0.82
-0.415180722891566	0.82
-0.42	0.822424242424242
-0.41	-0.817361963190184
-0.41	0.817361963190184
-0.4	-0.81239263803681
-0.395063291139241	-0.81
-0.395063291139241	0.81
-0.4	0.81239263803681
-0.39	-0.807515527950311
-0.39	0.807515527950311
-0.38	-0.802732919254658
-0.374133333333333	-0.8
-0.374133333333333	0.8
-0.38	0.802732919254658
-0.37	-0.798050314465409
-0.37	0.798050314465409
-0.36	-0.793459119496855
-0.352253521126761	-0.79
-0.352253521126761	0.79
-0.36	0.793459119496855
-0.35	-0.788980891719745
-0.35	0.788980891719745
-0.34	-0.784585987261146
-0.34	0.784585987261146
-0.33	-0.78031847133758
-0.329230769230769	-0.78
-0.329230769230769	0.78
-0.33	0.78031847133758
-0.32	-0.776129032258065
-0.32	0.776129032258065
-0.31	-0.772064516129032
-0.304754098360656	-0.77
-0.304754098360656	0.77
-0.31	0.772064516129032
-0.3	-0.768104575163399
-0.3	0.768104575163399
-0.29	-0.764248366013072
-0.29	0.764248366013072
-0.28	-0.760522875816994
-0.278545454545455	-0.76
-0.278545454545455	0.76
-0.28	0.760522875816994
-0.27	-0.756887417218543
-0.27	0.756887417218543
-0.26	-0.753377483443709
-0.25	-0.75
-0.25	0.75
-0.26	0.753377483443709
-0.25	-0.75
-0.25	-0.75
-0.25	-0.75
-0.25	0.75
-0.25	0.75
-0.25	0.75
-0.24	-0.746711409395973
-0.24	0.746711409395973
-0.23	-0.743557046979866
-0.23	0.743557046979866
-0.22	-0.740536912751678
-0.218139534883721	-0.74
-0.218139534883721	0.74
-0.22	0.740536912751678
-0.21	-0.737619047619048
-0.21	0.737619047619048
-0.2	-0.734829931972789
-0.2	0.734829931972789
-0.19	-0.732176870748299
-0.181351351351351	-0.73
-0.181351351351351	0.73
-0.19	0.732176870748299
-0.18	-0.729655172413793
-0.18	0.729655172413793
-0.17	-0.727241379310345
-0.17	0.727241379310345
-0.16	-0.724965517241379
-0.16	0.724965517241379
-0.15	-0.722827586206897
-0.15	0.722827586206897
-0.14	-0.720827586206897
-0.135555555555555	-0.72
-0.135555555555555	0.72
-0.14	0.720827586206897
-0.13	-0.718951048951049
-0.13	0.718951048951049
-0.12	-0.717202797202797
-0.12	0.717202797202797
-0.11	-0.715594405594406
-0.11	0.715594405594406
-0.1	-0.714125874125874
-0.1	0.714125874125874
-0.09	-0.712797202797203
-0.09	0.712797202797203
-0.08	-0.711608391608392
-0.08	0.711608391608392
-0.07	-0.710559440559441
-0.0638461538461535	-0.71
-0.0638461538461535	0.71
-0.07	0.710559440559441
-0.0599999999999999	-0.709645390070922
-0.0599999999999999	0.709645390070922
-0.0499999999999999	-0.70886524822695
-0.0499999999999999	0.70886524822695
-0.04	-0.70822695035461
-0.04	0.70822695035461
-0.03	-0.707730496453901
-0.03	0.707730496453901
-0.02	-0.707375886524823
-0.02	0.707375886524823
-0.01	-0.707163120567376
-0.01	0.707163120567376
0	-0.70709219858156
0	0.70709219858156
0.01	-0.707163120567376
0.01	0.707163120567376
0.02	-0.707375886524823
0.02	0.707375886524823
0.03	-0.707730496453901
0.03	0.707730496453901
0.04	-0.70822695035461
0.04	0.70822695035461
0.05	-0.70886524822695
0.05	0.70886524822695
0.0638461538461536	-0.71
0.0600000000000001	-0.709645390070922
0.0600000000000001	0.709645390070922
0.0638461538461536	0.71
0.0700000000000001	-0.710559440559441
0.0700000000000001	0.710559440559441
0.0800000000000001	-0.711608391608392
0.0800000000000001	0.711608391608392
0.0900000000000001	-0.712797202797203
0.0900000000000001	0.712797202797203
0.1	-0.714125874125874
0.1	0.714125874125874
0.11	-0.715594405594406
0.11	0.715594405594406
0.12	-0.717202797202797
0.12	0.717202797202797
0.135555555555555	-0.72
0.13	-0.718951048951049
0.13	0.718951048951049
0.135555555555555	0.72
0.14	-0.720827586206897
0.14	0.720827586206897
0.15	-0.722827586206897
0.15	0.722827586206897
0.16	-0.724965517241379
0.16	0.724965517241379
0.17	-0.727241379310345
0.17	0.727241379310345
0.181351351351351	-0.73
0.18	-0.729655172413793
0.18	0.729655172413793
0.181351351351351	0.73
0.19	-0.732176870748299
0.19	0.732176870748299
0.2	-0.734829931972789
0.2	0.734829931972789
0.218139534883721	-0.74
0.21	-0.737619047619048
0.21	0.737619047619048
0.218139534883721	0.74
0.22	-0.740536912751678
0.22	0.740536912751678
0.23	-0.743557046979866
0.23	0.743557046979866
0.25	-0.75
0.24	-0.746711409395973
0.24	0.746711409395973
0.25	0.75
0.25	-0.75
0.25	-0.75
0.25	-0.75
0.25	0.75
0.25	0.75
0.25	0.75
0.26	-0.753377483443709
0.26	0.753377483443709
0.278545454545455	-0.76
0.27	-0.756887417218543
0.27	0.756887417218543
0.278545454545455	0.76
0.28	-0.760522875816994
0.28	0.760522875816994
0.29	-0.764248366013072
0.29	0.764248366013072
0.304754098360656	-0.77
0.3	-0.768104575163399
0.3	0.768104575163399
0.304754098360656	0.77
0.31	-0.772064516129032
0.31	0.772064516129032
0.329230769230769	-0.78
0.32	-0.776129032258065
0.32	0.776129032258065
0.329230769230769	0.78
0.33	-0.78031847133758
0.33	0.78031847133758
0.34	-0.784585987261146
0.34	0.784585987261146
0.352253521126761	-0.79
0.35	-0.788980891719745
0.35	0.788980891719745
0.352253521126761	0.79
0.36	-0.793459119496855
0.36	0.793459119496855
0.374133333333334	-0.8
0.37	-0.798050314465409
0.37	0.798050314465409
0.374133333333334	0.8
0.38	-0.802732919254658
0.38	0.802732919254658
0.395063291139241	-0.81
0.39	-0.807515527950311
0.39	0.807515527950311
0.395063291139241	0.81
0.4	-0.81239263803681
0.4	0.81239263803681
0.415180722891566	-0.82
0.41	-0.817361963190184
0.41	0.817361963190184
0.415180722891566	0.82
0.42	-0.822424242424242
0.42	0.822424242424242
0.434597701149425	-0.83
0.43	-0.827575757575758
0.43	0.827575757575758
0.434597701149425	0.83
0.44	-0.832814371257485
0.44	0.832814371257485
0.453406593406593	-0.84
0.45	-0.83814371257485
0.45	0.83814371257485
0.453406593406594	0.84
0.46	-0.843550295857988
0.46	0.843550295857988
0.471684210526316	-0.85
0.47	-0.84905325443787
0.47	0.84905325443787
0.471684210526316	0.85
0.489484536082474	-0.86
0.48	-0.854619883040936
0.48	0.854619883040936
0.489484536082474	0.86
0.49	-0.86028901734104
0.49	0.86028901734104
0.506831683168317	-0.87
0.5	-0.866011560693642
0.5	0.866011560693642
0.506831683168317	0.87
0.51	-0.871828571428571
0.51	0.871828571428571
0.523809523809524	-0.88
0.52	-0.877714285714286
0.52	0.877714285714286
0.523809523809524	0.88
0.53	-0.883672316384181
0.53	0.883672316384181
0.54045871559633	-0.89
0.54	-0.889717514124294
0.54	0.889717514124294
0.540458715596331	0.89
0.556756756756757	-0.9
0.55	-0.895810055865922
0.55	0.895810055865922
0.556756756756757	0.9
0.56	-0.901988950276243
0.56	0.901988950276243
0.572782608695652	-0.91
0.57	-0.908232044198895
0.57	0.908232044198895
0.572782608695652	0.91
0.588547008547009	-0.92
0.58	-0.914535519125683
0.58	0.914535519125683
0.588547008547008	0.92
0.59	-0.920918918918919
0.59	0.920918918918919
0.604049586776859	-0.93
0.6	-0.927351351351351
0.6	0.927351351351351
0.604049586776859	0.93
0.619349593495935	-0.94
0.61	-0.933850267379679
0.61	0.933850267379679
0.619349593495935	0.94
0.62	-0.94042328042328
0.62	0.94042328042328
0.634409448818898	-0.95
0.63	-0.947037037037037
0.63	0.947037037037037
0.634409448818898	0.95
0.649302325581395	-0.96
0.64	-0.953717277486911
0.64	0.953717277486911
0.649302325581395	0.96
0.65	-0.960466321243523
0.65	0.960466321243523
0.663984962406015	-0.97
0.66	-0.967253886010363
0.66	0.967253886010363
0.663984962406015	0.97
0.678518518518518	-0.98
0.67	-0.974102564102564
0.67	0.974102564102564
0.678518518518518	0.98
0.68	-0.981015228426396
0.68	0.981015228426396
0.692877697841727	-0.99
0.69	-0.987969543147208
0.69	0.987969543147208
0.70709219858156	-1
0.7	-0.994974874371859
*/